﻿@{
    ViewBag.Title = "ShowReturnGoods";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">

            <label class="layui-form-label">产品单号</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="ProductCode" lay-verify="required" placeholder="请输入产品单号" autocomplete="off" class="layui-input">
            </div>


            <label class="layui-form-label">销售单号</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="SalesOrderCode" lay-verify="required" placeholder="请输入销售单号" autocomplete="off" class="layui-input">
            </div>

            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="ProductName" lay-verify="required" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
            </div>

            <button type="button" id="getReturnGoods" class="layui-btn layui-bg-blue">查询</button>
            <button type="reset" id="restReturnGoods" class="layui-btn">重置</button>
            <button type="button" class="layui-btn layui-bg-red" lay-event="del">删除</button>
            <button type="button" class="layui-btn layui-bg-red" lay-event="update">导出</button>
        </div>
        
        <table class="layui-hide" id="ReturnGoods" lay-filter="test">
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">退货</a>
        </script>
    </form>

    <!-- 引入 layui.js -->
    <script src="~/libs/jquery/jquery.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    @*  显示 *@
    <script>

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格
                , util = layui.util
                , datas = [];
            var $ = layui.$;
            var form = layui.form;

            //显示
            showReturnGoods = function () {
                layui.use(function () {
                    // 创建表格实例
                    table.render({
                        elem: '#ReturnGoods',
                        url: '/ReturnGoods/GetReturnService', // 此处为静态模拟数据，实际使用时需换成真实接口
                        where: {
                            SalesOrderCode: $("#SalesOrderCode").val(),
                            ProductCode: $("#ProductCode").val(),
                            ProductName: $("#ProductName").val(),                         
                        },
                        cols: [[  
                            { type: 'checkbox', fixed: 'left' },
                            { field: 'ProductName', title: '产品名称' },
                            { field: 'ProductCode', title: '产品编号' },
                            { field: 'ProductSpecification', title: '产品规格' },
                            { field: 'Unit', title: '单位' },
                            { field: 'UnitPrice', title: '单价' },
                            { field: 'ReturnQuantity', title: '退货数' },
                            {
                                field: 'UnitPrice', title: '总额', templet: function (row) {
                                    return row.UnitPrice * row.ReturnQuantity
                                }
                            },
                            { field: 'SalesOrderCode', title: '销售单号' },
                            { field: 'CustomerName', title: '客户名称' },
                            { fixed: "right", title: '操作', align: 'center', toolbar: '#barDemo' }
                        ]],
                        done: function () {
                            var id = this.id;
                            table.on('checkbox(test)', function (obj) {
                                datas.push(obj.data);
                            });
                        }
                    });
                });
            }
            //显示
            showReturnGoods();
            //查询
            $("#getReturnGoods").on("click", function () {
                showReturnGoods();
            })
            //重置
            $("#restReturnGoods").on("click", function () {
                showReturnGoods();
            })

            //查看
                table.on('tool(test)', function (obj) {
                    var data = obj.data//获取当前数据
                            , layEvent = obj.event;//获取lay-event获取对应的值
                        if (layEvent == 'delete') {
                            layer.confirm('确定删除当前退货信息吗？', function (index) {
                                $.ajax({
                                    url: "/ReturnGoods/DelReturnGood?id=" + data.Id,
                                    type: "get",
                                    success: res => {
                                        if (res > 0) {
                                            alert("退货成功");
                                            obj.del();
                                            layer.close(index);
                                        }
                                    }
                                });
                            })
                        }
                                else if (layEvent == 'show') {
                            console.log(data.Id)
                            layer.open({
                                type: 2,
                                area: ['800px', '500px'],
                                resize: false,
                                shadeClose: true,
                                title: '查看退货信息',
                                content: '/ReturnGoods/GetReturnGood?id=' + data.Id
                                    })
                        }
                    });

        });
    </script>
</body>
</html>